package com.mlf.observer.spring;

import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

// 统计服务监听器 （异步处理）
@Component
public class StatisticsServiceListener {

    @Async
    @EventListener
    public void handleUserRegisteredEvent(UserRegisteredEvent event) {
        // 统计服务处理
        System.out.println("异步处理： 更新用户注册统计数据");
        // 模拟耗时
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        System.out.println("异步处理完成: " + event.getUsername() + "的统计已更新");

    }
}
